<?php

// this file must be stored in:
// protected/components/WebUser.php

class WebUser extends CWebUser {

    // Store model to not repeat query.
    private $_model;
    
    public function isSuperuser()
    {
        return $this->loadUser(Yii::app()->user->id)->role == Yii::app()->params['SUPER']; 
    }

    public function getRole() {
        return $this->loadUser(Yii::app()->user->id)->role;
    }
    
    // Load user model.
    protected function loadUser($id=null)
    {
        if($this->_model===null)
        {
            if($id!==null)
                $this->_model=User::model()->findByPk($id);
        }
        return $this->_model;
    }

	public function logout($destroySession= true)
	    {
	        // I always remove the session variable model.
	        Yii::app()->getSession()->remove('model');
	        parent::logout();
	    }
}
